﻿using System;
using System.Windows.Forms;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKView;

namespace SectionSignAndFilled.StairsClearHeightDimension
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdDeleteStairsClearHeightDimension : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			int num = Convert.ToInt32(commandData.Application.Application.VersionNumber);
			if (num < 2014)
			{
				message = "此功能只在Revit2014及其以上版本可用。";
				return Autodesk.Revit.UI.Result.Failed;
			}
			CmdViewType types = CmdViewType.Section;
			if (SwitchView.SetUsableView(types, commandData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			Document document = commandData.Application.ActiveUIDocument.Document;
			Transaction transaction = new Transaction(document, "DimDelete");
			transaction.Start();
			try
			{
				ElementId id = document.ActiveView.Id;
				StairsClearHeightMgr.DeleteStairsClearHeightDimension(document, id);
				transaction.Commit();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message, "盈建科提示");
				transaction.RollBack();
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
